<template>
    <div class="login" style="">
        <el-form :model="ruleForm2" status-icon :rules="rules2" ref="ruleForm2" label-width="100px" class="demo-ruleForm">
            <el-form-item label="用户名" prop="username">
                <el-input type="username" v-model="ruleForm2.username" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="passworde">
                <el-input type="password" v-model="ruleForm2.passworde" auto-complete="off"></el-input>
            </el-form-item>
            <el-form-item label="验证码" prop="login_code">
                <el-input v-model="ruleForm2.login_code"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm2')" >提交</el-button>
                <el-button @click="resetForm('ruleForm2')">重置</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>


<script>
    export default {
        data() {
            var validateCode = (rule, value, callback) => {
                if (value==='') {
                    return callback(new Error('验证码不能为空'));
                }
                else{
                    callback();
                }

            };
            var validateUser= (rule, value, callback) => {
                if (value==='') {
                    callback(new Error('请输入用户名'));
                }
                else{
                    callback();
                }
            };
            var validatePass = (rule, value, callback) => {
                if (value==='') {
                    callback(new Error('请再次输入密码'));
                }
                else{
                    callback();
                }
            };
            return {
                ruleForm2: {
                    loginging:'false',
                    username: '',
                    passworde: '',
                    login_code: ''
                },
                rules2: {
                    username: [
                        { validator: validateUser, trigger: 'blur' }
                    ],
                    passworde: [
                        { validator: validatePass, trigger: 'blur' }
                    ],
                    login_code: [
                        { validator: validateCode, trigger: 'blur' }
                    ]
                }
            };
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if ((valid)){
                        alert("ok")
                    }

                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();

            },
        },

    }
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    .login{
        width: 300px;
    }
</style>
